﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public static class MathExtension
{
    /// <summary>
    /// 换算平均数
    /// </summary>
    /// <param name="TArray"></param>
    /// <param name="Cilp"></param>
    /// <returns></returns>
    public static byte[] ConvertNumberAverage(byte[] TArray, int Cilp)
    {
        byte[] average = new byte[TArray.Length];
        if (Cilp > TArray.Length)
        {
           for(int a= 0; a< TArray.Length; a++)
            {
                average[a] = TArray[a];
            }
            return average;//小文件统统后为0。
        }

        int nubmer = 0;

        byte[] t = new byte[Cilp];
        for (int b = 0; b < Cilp; b++)
        {
            for (int a = 0; a < TArray.Length / Cilp; a++)
            {
                nubmer += TArray[a + (TArray.Length / Cilp * b)];
            }
            t[b] = Convert.ToByte((nubmer / (TArray.Length / Cilp)));
            nubmer = 0;
        }
        return t;
    }
}

